package com.qq2008.game.stzb.server;

import com.qq2008.game.stzb.jdo.Event;
import com.qq2008.game.stzb.jdo.Player;
import com.qq2008.game.stzb.jdo.Role;
import com.qq2008.game.stzb.jdo.Room;

import java.util.HashMap;
import java.util.Map;

// 事件管理器
public class EventServer {

    private Map<Integer, Event> eventMap = new HashMap<>();

    // 复活
    public static void roleRelive(Role role) {
        role.setHp(role.getMaxHP());
        role.setDead(false);
        role.setBattle(null);
        role.setRoomId(104);
    }

    // 治疗
    public static Role roleHPTreat(Role role) {
        role.setHp(role.getMaxHP());
        return role;
    }

    // 回魔
    public static Role roleMPTreat(Role role) {
        role.setMp(role.getMaxMP());
        return role;
    }

    // 获取随机道具 todo
    public static Role giveRandItem(Role role) {
        role.setMp(role.getMaxMP());
        return role;
    }

    // 进入战斗 todo
    public static void battle(Player attacker, Player defener, Room room) {

    }

    Map<Integer, Event> getEventMap() {
        Event event1 = new Event(1, "脚本错误", "", "未找到脚本", 0, "继续");
        Event event100 = new Event(100, "复活", "roleRelive", "恍惚", 0, "继续");
        eventMap.put(event1.getId(), event1);
        eventMap.put(event100.getId(), event100);
        return eventMap;
    }

    // 根据脚本Id获取脚本
    private Event getEvent(int eventId) {
        return eventMap.get(eventId);
    }

    // 根据脚本Id执行脚本
    Event doEvent(int eventId) {
        Event event = getEvent(eventId);
        if (null == event) {
            return getEvent(1);
        }

        String funName = event.getFun().trim();
        if ("".equals(funName)) {
            return getEvent(1);
        }
        //Class<?> clazz = EventServer.class;
        //Object o = clazz.newInstance();
        //Method method = Class.getMethod(funName, clazz);

        return null;
    }

}
